package com.itheima.web.controller.front;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.itheima.domain.front.ExamQuestion;
import com.itheima.domain.store.Question;
import com.itheima.web.controller.BaseServlet;
import com.itheima.web.controller.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @program: mm_exam_review
 * @description:
 * @author: zhanghz001
 * @create: 2020-11-16 14:35
 **/
@WebServlet("/exam/*")
public class ExamQuestionServlet extends BaseServlet {
    Logger logger = LoggerFactory.getLogger(MemberServlet.class);

    public Result applyPaper(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String json = JSON.parseObject(req.getInputStream(), String.class);
        JSONObject jsonObject = JSON.parseObject(json);
        String memberId = jsonObject.getObject("memberId", String.class);
        JSONArray jsonArray = jsonObject.getJSONArray("results");
        List<ExamQuestion> examQuestionList = jsonArray.toJavaList(ExamQuestion.class);
        boolean flag = examQuestionService.applyPaper(memberId, examQuestionList);

        return new Result(flag, "提交成功!");
    }

    public Result getPaper(HttpServletRequest req, HttpServletResponse resp) {
        //
        List<Question> list = examQuestionService.getPaper();
        return new Result(list, "获取成功!");
    }
}
